<template>
  <div class="bg-tabs-2">
    <div
      class="bg-tabs-item"
      :class="item.value === value ? 'bg-active' : 'bg-noactive'"
      @click="change(item)"
      v-for="item in tabs"
    >
      <!-- <div class="bg-tabs-item-icon" v-if="item.value === value"></div> -->
      <span :class="item.value === value ? 'active' : 'noactive'">
        {{ item.name }}
      </span>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    tabs: {
      type: Array,
      default: function () {
        return [
          {
            name: '种植面积',
            value: '1',
          },
          {
            name: '产量',
            value: '2',
          },
          {
            name: '产值',
            value: '3',
          },
          {
            name: '加工转化率',
            value: '4',
          },
        ]
      },
    },
    isCancel: {
      type: Boolean,
      default: true,
    },
    value: {
      type: String,
      default: '',
    },
  },
  data() {
    return {
      // value: '',
    }
  },
  model: {
    prop: 'value',
    event: 'change',
  },
  methods: {
    change(item) {
      // if (this.tabs.length === 1) return
      if (item.value === this.value && this.isCancel === true) {
        this.$emit('change', '')
      } else {
        this.$emit('change', item.value)
      }

      // this.$emit('change', this.value)
    },
  },
}
</script>
<style lang="scss">
.bg-tabs-2 {
  display: flex;
  align-items: center;
  gap: 6px;
  .bg-tabs-item {
    height: 26px;
    border-radius: 2px;
    opacity: 1;
    cursor: pointer;
    /* 自动布局 */
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 6px 8px;
    span.active {
      opacity: 1;
      font-family: Source Han Sans;
      font-size: 14px;
      font-weight: bold;
      line-height: 14px;
      text-align: center;
      letter-spacing: 0em;

      font-variation-settings: 'opsz' auto;
      font-feature-settings: 'kern' on;
      /* 纯白 */
      color: #ffffff;

      z-index: 0;
    }
    span.noactive {
      opacity: 0.8;
      font-family: 思源黑体;
      font-size: 14px;
      font-weight: normal;
      line-height: 14px;
      text-align: center;
      letter-spacing: 0em;

      font-variation-settings: 'opsz' auto;
      font-feature-settings: 'kern' on;
      /* 纯白 */
      color: #ffffff;

      z-index: 0;
    }
  }
  .bg-active {
    background: rgba(59, 214, 172, 0.49);
  }
  .bg-noactive {
    background: rgba(59, 214, 172, 0.1);
  }
}
</style>
